package com.chenyaowei.web.controller.marketing.coupon;

import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.annotation.RepeatSubmit;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.core.page.TableDataInfo;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.marketing.domain.CywCouponHistory;
import com.chenyaowei.marketing.request.CouponPickUpRequest;
import com.chenyaowei.marketing.service.ICywCouponHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 优惠券领取历史记录Controller
 *
 * @author 陈耀威
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/marketing/couponHistory")
public class CywCouponHistoryController extends BaseController
{
    @Autowired
    private ICywCouponHistoryService cywCouponHistoryService;


    @GetMapping("/list/currentUser")
    public TableDataInfo listByMemberId(CywCouponHistory cywCouponHistory)
    {
        startPage();
        cywCouponHistory.setMemberId(getUserId());
        List<CywCouponHistory> list = cywCouponHistoryService.selectCywCouponHistoryList(cywCouponHistory);
        return getDataTable(list);
    }

    /**
     * 查询优惠券领取历史记录列表
     */
//    @PreAuthorize("@ss.hasPermi('coupon:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywCouponHistory cywCouponHistory)
    {
        startPage();
        List<CywCouponHistory> list = cywCouponHistoryService.selectCywCouponHistoryList(cywCouponHistory);
        return getDataTable(list);
    }

    /**
     * 导出优惠券领取历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('coupon:history:export')")
    @Log(title = "优惠券领取历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywCouponHistory cywCouponHistory)
    {
        List<CywCouponHistory> list = cywCouponHistoryService.selectCywCouponHistoryList(cywCouponHistory);
        ExcelUtil<CywCouponHistory> util = new ExcelUtil<CywCouponHistory>(CywCouponHistory.class);
        util.exportExcel(response, list, "优惠券领取历史记录数据");
    }

    /**
     * 获取优惠券领取历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('coupon:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywCouponHistoryService.selectCywCouponHistoryById(id));
    }

    /**
     * 新增优惠券领取历史记录
     */
//    @PreAuthorize("@ss.hasPermi('coupon:history:add')")
    @RepeatSubmit
    @Log(title = "优惠券领取历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CouponPickUpRequest couponClaimRequest)
    {
        return toAjax(cywCouponHistoryService.couponPickUp(couponClaimRequest));
    }

    /**
     * 修改优惠券领取历史记录
     */
    @PreAuthorize("@ss.hasPermi('coupon:history:edit')")
    @Log(title = "优惠券领取历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywCouponHistory cywCouponHistory)
    {
        return toAjax(cywCouponHistoryService.updateCywCouponHistory(cywCouponHistory));
    }

    /**
     * 删除优惠券领取历史记录
     */
    @PreAuthorize("@ss.hasPermi('coupon:history:remove')")
    @Log(title = "优惠券领取历史记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywCouponHistoryService.deleteCywCouponHistoryByIds(ids));
    }
}
